<?php
    session_start();
    include_once '../../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $oid = $_REQUEST['oid'];
    $fec = $_REQUEST['fec'];
    $obs = utf8_decode($_REQUEST['obs']);
    $hora = $_REQUEST['hora'];
    $fecha = $_REQUEST['fecha'];
    
    $fecha2 = date('Y-m-d H:i:s',strtotime($fecha));
    
    $usuario = $_SESSION['usuario'];
    
    if($usuario == ""){
        
        print_r(json_encode(array('n'=>1)));
    }
    else{
        $count = "select count(*) as n from segasigcita where hcnsolexa = '".$oid."'";
        $res = $con->query($count);
        
         while($res2 = mssql_fetch_array($res)){
            $n = $res2['n'];
        }
        if($n == 0){
            $inser= "insert into segasigcita(hcnsolexa,asigobserv,usu_oid,asigfechar,asirea,asigfecha2)values('".$oid."','".$obs."','".$_SESSION['usuario']."',GETDATE(),'','".$fecha2."')";
             $con->query($inser);
        }else{
            $update = "update segasigcita
                        set asigfecha2 = '".$fecha2."',
                        asigobserv = '".$obs."',
                        asirea = 1
                      where hcnsolexa = '".$oid."'";
            $con->query($update);
        }
        
        print_r(json_encode(array('n'=>2)));
    }
    $con->cerrarConexion();
     
?>